/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package concurrent.adder;

/**
 *
 * @author harker777
 */
public class TaskDistributorImpl implements TaskDistributor {

	private Integer[] froms;
	private Integer[] tos;

	@Override
	public void distributeTasks(Integer threadsNumber, Integer arraySize) {
		froms = new Integer[threadsNumber];
		tos = new Integer[threadsNumber];

		Integer numbersPerThread = arraySize / threadsNumber;
		for (int i = 0; i < threadsNumber; i++) {
			froms[i] = i * numbersPerThread;
			tos[i] = (i + 1) * numbersPerThread - 1;
		}
		if (arraySize % threadsNumber != 0){
			Integer tasksLeft = (arraySize - (threadsNumber * numbersPerThread));
			tos[threadsNumber - 1] += tasksLeft;
		}

	}

	@Override
	public Integer[] getFroms() {
		return froms;
	}

	@Override
	public Integer[] getTos() {
		return tos;
	}
}
